package com.xbongbong.workflow.rabbitmq.consumer;

import com.xbongbong.schedule.pojo.dto.ScheduleTaskRabbitmqDTO;
import com.xbongbong.schedule.service.ScheduleTaskService;
import com.xbongbong.workflow.rabbitmq.binders.ScheduleTaskMqConsumerBinder;
import com.xbongbong.workflow.rabbitmq.constant.ScheduleTaskMqConsumerConstant;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service("scheduleTaskListener")
@EnableBinding(ScheduleTaskMqConsumerBinder.class)
public class ScheduleTaskListener {

    @Resource
    private ScheduleTaskService scheduleTaskService;

    @StreamListener(value = ScheduleTaskMqConsumerConstant.SCHEDULE_TASK_INPUT)
    public void scheduleTaskReceive(ScheduleTaskRabbitmqDTO scheduleTaskRabbitmqDTO) {
        scheduleTaskService.handleScheduleTask(scheduleTaskRabbitmqDTO);
    }

    @StreamListener(value = ScheduleTaskMqConsumerConstant.SCHEDULE_TASK_IMMEDIATELY_INPUT)
    public void scheduleTaskImmediatelyReceive(ScheduleTaskRabbitmqDTO scheduleTaskRabbitmqDTO) {
        scheduleTaskService.handleScheduleTask(scheduleTaskRabbitmqDTO);
    }
}
